package work.sajor.wechatpush.util;

import org.apache.commons.lang3.StringUtils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @ClassName CaiHongPi
 *@Description TODO
 *@Author ysg
 *@Date 2024/6/2 16:00
 */
public class CaiHongPi {
    private static String url = "https://api.vvhan.com/api/text/love?type=json";
    private static List<String> jinJuList = new ArrayList<>();
    private static String name = "我的宝";




//    /**
//     * @return https://api.vvhan.com/
//     * 免费情话
//     */
//    public static JSONObject getCaiHongPi() {
//        String result = null;
//        JSONObject todaylist = new JSONObject();
//        try {
//            result = HttpUtil.getUrl("https://api.vvhan.com/api/text/love?type=json");
//            JSONObject jsonObject = JSONObject.parseObject(result);
//            JSONObject arr = jsonObject.getJSONObject("data");
//            todaylist.put("content", arr.getString("content"));
//            System.out.println("-----------"+todaylist);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return todaylist;
//    }




    /**
     * 载入金句库
     */
    static {
        InputStream inputStream = CaiHongPi.class.getClassLoader().getResourceAsStream("static/jinju.txt");
        try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))) {
            String str = "";
            String temp = "";
            while ((temp = br.readLine()) != null) {
                if (!StringUtils.isEmpty(temp)) {
                    str = str + "\r\n" + temp;
                } else {
                    jinJuList.add(str);
                    str = "";
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getJinJu() {
        Random random = new Random();
        return jinJuList.get(random.nextInt(jinJuList.size()));
    }

    public static void main(String[] args) {
        System.out.println(getJinJu());
//        System.out.println(getCaiHongPi());
    }
}
